import re
import sys
def main():
  num_hidden_layers=5
  base_dnn="exp_pdnn/dnn_fmllr/nnet.finetune.tmp"
  str_ptr="exp_pdnn/100_Str_25_dnn_fmllr_128/dnn.ptr"
  warm_ptr="exp_pdnn/warm_100_Str_25_dnn_fmllr_128/dnn.ptr"
  
  base_dnn_file=open(base_dnn,'r')
  str_ptr_file=open(str_ptr,'r')
  temp=[]
  ptr_file=open(warm_ptr,'w')
  
  temp_num=2*num_hidden_layers
  a=','.join(str(i) for i in xrange(1,temp_num) if i % 2 ==1)
  a=map(int,a.split(','))

  b=','.join(str(i) for i in xrange(1,temp_num+1) if i % 2 ==0)
  b=map(int,b.split(','))
  
  print 'processing the base dnn file '  
  for num_line,line in enumerate(base_dnn_file):
    #line = line.rstrip()
    #f (num_line ==0):
    # temp_file.write(line)
    
    if (num_line in a):
      line = line.replace('W','W1')
      temp.append(line)
      #temp_file.write(line)

    elif (num_line in b):
      line = line.replace('b','b1')
      temp.append(line)
  
  print len(temp)


  temp_num=5*num_hidden_layers
  c=','.join(str(i) for i in xrange(1,temp_num) if i % 5 in (1,4))
  c=map(int,c.split(','))
  
  temp_index=0
  print 'processing the str_ptr_file'
  for num_line,line in enumerate(str_ptr_file):
    if (num_line in c):
      print temp_index
      ptr_file.write(temp[temp_index])
      temp_index=temp_index+1

    else:
      ptr_file.write(line)
    

if __name__=="__main__":
    main()

